package lg.minecraft.plugin.pokemonmenu.tasks;

import lg.minecraft.plugin.pokemonmenu.LGPokemonMenu;
import lg.minecraft.plugin.pokemonmenu.manager.DisplayPokemonManger;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

public class PokemonDisplayCleanupTask extends BukkitRunnable {

    private BukkitTask task;

    public void start() {
        if (task != null) task.cancel();
        task = runTaskTimer(LGPokemonMenu.getInstance(), 20, 20); // 每秒执行一次
    }

    public void stop() {
        if (task != null) {
            task.cancel();
            task = null;
        }
    }

    @Override
    public void run() {
        // 清理缓存中的过期宝可梦数据
        DisplayPokemonManger.INSTANCE.removeExpiredKeysBeforeNow();

        // 清理冷却记录
        DisplayPokemonManger.INSTANCE.purgeExpiredCooldowns();
    }

}
